package example;

public class SecretText {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		InputValue input = new InputValue();
		String aString = input.inputString("Enter message:");
		StringBuffer encrypeMessage = encrypeMessage(aString);
		System.out.println("EncrypeMessage: " + encrypeMessage);
		String encrypeMessageString = encrypeMessage.toString();
		StringBuffer decrypeMessage = decrypeMessage(encrypeMessageString);
		System.out.println("DecrypeMessage: " + decrypeMessage);
	}

	public static StringBuffer encrypeMessage(String aString) {

		StringBuffer result = new StringBuffer();

		for (int i = 0; i < aString.length(); i++) {
			int key = (int) (Math.random() * 100);
			result.append((char) key + "" + (char) (aString.charAt(i) + key));
		}
		return result;
	}

	public static StringBuffer decrypeMessage(String aString) {
		StringBuffer result = new StringBuffer();

		for (int i = 0; i < aString.length(); i += 2) {
			result.append((char) (aString.charAt(i + 1) - (int) aString
					.charAt(i)));
		}
		return result;
	}
}
